//
//  ViewController.m
//  UI23_02_NSNotificationCenter
//
//  Created by Scott on 16/4/11.
//  Copyright © 2016年 Scott. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UITextField *textField;


@property (weak, nonatomic) IBOutlet NSLayoutConstraint *buttom;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    [self notiCenter];
}



#pragma mark - NSNotificationCenter 
- (void)notiCenter {
    
    // 获取通知中心
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleTextFieldFrame:) name:UIKeyboardWillShowNotification object:nil];

}

- (void)handleTextFieldFrame:(NSNotification *)noti {
    
    NSLog(@"%@", noti);
    
    CGFloat height = [[noti.userInfo objectForKey:@"UIKeyboardFrameEndUserInfoKey"] CGRectValue].size.height;
    
    NSLog(@"%f", height);
    

    
    // 重新计算textField 位置.
//    self.textField.frame = CGRectMake(20, 300, 100, 100);
    
    self.textField.translatesAutoresizingMaskIntoConstraints = NO;
    
    self.buttom.constant = 400;
    
    [UIView animateWithDuration:0.1 animations:^{
        
        
        [self.view layoutIfNeeded];
        
    }];
    
    
    NSLog(@"constant: %f", self.buttom.constant);
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
